import os, sys, pygame
from pygame.locals import *
from 加载程序 import load_image

LIFETIME = 300

#旋转的痕迹。
def rot_center(image, rect, angle):
        """在保持图像中心的情况下旋转图像"""
        rot_image = pygame.transform.rotate(image, angle)
        rot_rect = rot_image.get_rect(center=rect.center)
        return rot_image,rot_rect

#初始化，加载轨道图像。
def initialize():
    global tracks_img
    tracks_img = load_image('轨道.png', False)

#跟踪
class Track(pygame.sprite.Sprite):
    def __init__(self, car_x, car_y, angle):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = rot_center(tracks_img, tracks_img.get_rect(), angle)
        self.lifetime = LIFETIME
        self.screen = pygame.display.get_surface()
        self.x = car_x  + 3 
        self.y = car_y  + 20
        self.rect.topleft = self.x, self.y

    def update(self, cam_x, cam_y):
        self.rect.topleft = self.x - cam_x, self.y - cam_y
        self.lifetime = self.lifetime - 1

        if (self.lifetime < 1):
            pygame.sprite.Sprite.kill(self)
        

